package tp1.relatorio;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import java.util.ArrayList;
import tp1.Relatorio;
import tp1.models.Linha;

/**
 *
 * @author tulio
 */
public class RelatorioLinhas extends Relatorio{

    private ArrayList<Linha> linhas;

    public ArrayList<Linha> getLinhas() {
        return linhas;
    }

    public void setLinhas(ArrayList<Linha> linhas) {
        this.linhas = linhas;
    }

    @Override
    public void escrever() throws DocumentException{
        int row = 1;
        PdfPCell cell;
        
        String cpf = this.linhas.get(0).getCliente().getCpf();
        String nome = this.linhas.get(0).getCliente().getNome();
        String endereco = this.linhas.get(0).getCliente().getEndereco();        

        this.doc.add(new Phrase("CPF: ", FontFactory.getFont(FontFactory.HELVETICA, 9)));
        this.doc.add(new Phrase(cpf + "\n", FontFactory.getFont(FontFactory.HELVETICA, 8)));
        this.doc.add(new Phrase("Nome: ", FontFactory.getFont(FontFactory.HELVETICA, 9)));
        this.doc.add(new Phrase(nome + "\n", FontFactory.getFont(FontFactory.HELVETICA, 8)));
        this.doc.add(new Phrase("Endereço: ", FontFactory.getFont(FontFactory.HELVETICA, 9)));
        this.doc.add(new Phrase(endereco + "\n\n\n", FontFactory.getFont(FontFactory.HELVETICA, 8)));
        
        PdfPTable table = new PdfPTable(6);
        table.setHeaderRows(1);

        String[] headerStrings = new String[] { " - ", "Número", "Data de ativação", "Data de cancelamento",
            "Código do plano", "Plano"};
        
        for (String header : headerStrings) {
             PdfPCell headerCell = new PdfPCell(new Phrase(header, FontFactory.getFont(FontFactory.HELVETICA, 9)));
             headerCell.setGrayFill(0.7f);
             table.addCell(headerCell);
        }
        for(Linha l: this.linhas){
            cell = new PdfPCell(new Phrase(Integer.toString(row), FontFactory.getFont(FontFactory.HELVETICA, 8)));
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(l.getNumero(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(l.getDataDeAtivacao().toString(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
            table.addCell(cell);
            if(l.getDataDeCancelamento() == null){
                cell = new PdfPCell(new Phrase("Linha ativa", FontFactory.getFont(FontFactory.HELVETICA, 8)));
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(l.getDataDeCancelamento().toString(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
                table.addCell(cell);
            }
            cell = new PdfPCell(new Phrase(Integer.toString(l.getPlano().getCodigo()), FontFactory.getFont(FontFactory.HELVETICA, 8)));
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(l.getPlano().getDescricao(), FontFactory.getFont(FontFactory.HELVETICA, 8)));
            table.addCell(cell);
        }
        this.doc.add(table);
    }
  
}
